//
// Created by yangchao on 2022/4/20.
// 7. 整数反转: https://leetcode-cn.com/problems/reverse-integer/
//

#include <climits>

//关键是如何获取末尾的数字？：取模
class Reverse {
public:
    int reverse(int x) {
        long res = 0;
        while(x != 0) {
            int tmp = x % 10;
            res = res * 10 + tmp;
            x /= 10;
        }
        if  (res < INT_MIN || res > INT_MAX) return 0;
        return (int)res;
    }
};
